chrom_wid <- 0.05
thinw <- 0.28
blstw <- 0.48

load("./EH23ideo.RData")
#
pEH23

load("./EH23ideo_ahplot.RData")
ahplot

ahplot + ggplot2::scale_color_brewer(palette="Paired") 
## Scale for colour is already present.
## Adding another scale for colour, which will replace the existing scale.

ahplot + ggplot2::scale_color_brewer(palette="Paired", ggplot2::aes(alpha=0.04))
## Scale for colour is already present.
## Adding another scale for colour, which will replace the existing scale.

#  scale_color_manual( values = my_pal )
tbl1 <- read.table("EH23a_EH23b_ortholog_blast_fractionation.txt", sep = " ")
tbl1[1:3, ]
##                         V1                       V2   V3
## 1 EH23a.chr1.v1.g000010.t1 EH23b.chr1.v1.g000010.t1 chr1
## 2 EH23a.chr1.v1.g000020.t1 EH23b.chr1.v1.g000020.t1 chr1
## 3 EH23a.chr1.v1.g000030.t1 EH23b.chr1.v1.g000030.t1 chr1
all(sub("EH23a\\.", "", tbl1[, 1]) == sub("EH23b\\.", "", tbl1[, 2]))
## [1] FALSE
tbl2 <- read.table("quant.tsv", header = TRUE, sep = "\t")
tbl2[1:3, ]
##              Sample                     Name Length EffectiveLength      TPM
## 1 EH23_Early_Flower EH23a.chr1.v1.g000010.t1   3063        2849.169 2.464884
## 2 EH23_Early_Flower EH23a.chr1.v1.g000020.t1    768         554.402 0.000000
## 3 EH23_Early_Flower EH23a.chr1.v1.g000030.t1   1371        1157.169 1.367500
##   NumReads
## 1  124.266
## 2    0.000
## 3   28.000
tbl2[1:3, ]
##              Sample                     Name Length EffectiveLength      TPM
## 1 EH23_Early_Flower EH23a.chr1.v1.g000010.t1   3063        2849.169 2.464884
## 2 EH23_Early_Flower EH23a.chr1.v1.g000020.t1    768         554.402 0.000000
## 3 EH23_Early_Flower EH23a.chr1.v1.g000030.t1   1371        1157.169 1.367500
##   NumReads
## 1  124.266
## 2    0.000
## 3   28.000
table(tbl2$Sample)
## 
##    EH23_Early_Flower         EH23_Foliage EH23_Foliage_12light 
##                76968                76968                76968 
##     EH23_Late_Flower           EH23_Roots       EH23_Shoottips 
##                76968                76968                76968
nrow(tbl2)
## [1] 461808
my_chroms <- sub("\\.v1.+", "", tbl2$Name)
table(my_chroms)
## my_chroms
## EH23a.chr1 EH23a.chr2 EH23a.chr3 EH23a.chr4 EH23a.chr5 EH23a.chr6 EH23a.chr7 
##      30378      24630      24186      26208      22932      23406      18348 
## EH23a.chr8 EH23a.chr9 EH23a.chrX EH23b.chr1 EH23b.chr2 EH23b.chr3 EH23b.chr4 
##      23358      21780      31686      25410      21978      21606      23232 
## EH23b.chr5 EH23b.chr6 EH23b.chr7 EH23b.chr8 EH23b.chr9 EH23b.chrX 
##      18828      22116      16068      22182      18240      25236
tbl2$CHROM <- sub("EH23.\\.", "", my_chroms)
tbl2$hap <- sub("\\.chr.", "", my_chroms)

hist(log2(tbl2$TPM))

hist(log2(tbl2$TPM[ tbl2$hap == "EH23a"]))

hist(tbl2$TPM[ tbl2$hap == "EH23a"])

#hist(log2(tbl2$NumReads))

hist(log2(tbl2$NumReads[ tbl2$hap == "EH23a"]), breaks = seq(-10, 25, by = 1))

hist(log2(tbl2$NumReads[ tbl2$hap == "EH23b"]), breaks = seq(-10, 25, by = 1))

library(ggplot2)

tbl2[1:3, ]
##              Sample                     Name Length EffectiveLength      TPM
## 1 EH23_Early_Flower EH23a.chr1.v1.g000010.t1   3063        2849.169 2.464884
## 2 EH23_Early_Flower EH23a.chr1.v1.g000020.t1    768         554.402 0.000000
## 3 EH23_Early_Flower EH23a.chr1.v1.g000030.t1   1371        1157.169 1.367500
##   NumReads CHROM   hap
## 1  124.266  chr1 EH23a
## 2    0.000  chr1 EH23a
## 3   28.000  chr1 EH23a
p <- ggplot(tbl2, aes( x = log2(TPM) ))
p <- p + geom_histogram()
p <- p + theme_bw()
p <- p + scale_y_continuous(name = "Count (K)", breaks = seq(0, 60e3, by = 20e3), labels = seq(0, 60, by = 20))
p
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 201382 rows containing non-finite values (`stat_bin()`).

#library(scales)
#
#p + scale_y_continuous(labels = scientific)

ggpubr

library(ggpubr)

ggarrange(
  plotlist = list(pEH23, ahplot),
  labels = c("A", "B"),
  label.x = 0,
  label.y = c(1, 1.1),
  ncol = 1, nrow = 2, 
  widths = 1, heights = c(2, 1)
)

library(ggpubr)

p1 <- ggarrange(
  plotlist = list(pEH23, ahplot),
  labels = c("A", "B"),
  label.x = 0,
  label.y = c(1, 1.1),
  ncol = 1, nrow = 2, 
  widths = 1, heights = c(2, 1)
)

p2 <- ggarrange(
  plotlist = list(p, p, p),
  labels = c("C", "D", "E"),
  label.x = 0,
  label.y = c(1, 1.1),
  ncol = 1, nrow = 3, 
  widths = 1, heights = c(2, 1, 1)
)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 201382 rows containing non-finite values (`stat_bin()`).
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 201382 rows containing non-finite values (`stat_bin()`).
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 201382 rows containing non-finite values (`stat_bin()`).
p3 <- ggarrange(
  plotlist = list(p1, p2),
#  labels = c("C", "D", "E"),
#  label.x = 0,
#  label.y = c(1, 1.1),
  ncol = 2, nrow = 1, 
  widths = c(2, 1), heights = 1)

p3

ggsave( filename = "EH23_ideo_exp.tiff", device = "tiff", 
        width = 6.5, 
        height = 6.5,
        #height = 9,
        units = "in", dpi = 300, 
        compression = "lzw")